from django.db import models
from django.contrib.auth.models import AbstractUser


class User(AbstractUser):
    #  AbstractUser这个类，也就是Django框架默认使用的一个用于管理用户的User类，这个类生成一个auth_user表。所以，要扩展用户属性，可以继承AbstractUser，在子类UserModel中实现扩展。
    # REQUIRED_FIELDS = ['id', 'username', 'email']
    GENDER_CHOICES = (
        ('M', '男'),
        ('F', '女'),
    )
    ROLE_CHOICES = (
        ('0', '管理员'),
        ('1', '普通用户'),
    )
    STATUS_CHOICES = (
        ('0', '正常'),
        ('1', '封号'),
    )

    user_types = ((1, 'NOMAL'),
                  (2, 'SVIP'),
                  (3, 'VVIP'))

    # user_type = models.SmallIntegerField('用户级别', choices=user_types, default=1)
    id = models.BigAutoField(primary_key=True)
    # username = models.CharField(max_length=50, null=True)
    #password = models.CharField(max_length=50, null=True)
    role = models.CharField(max_length=2, blank=True, null=True)
    status = models.CharField(max_length=1, choices=STATUS_CHOICES, default='0')
    nickname = models.CharField(blank=True, null=True, max_length=20)
    avatar = models.FileField(upload_to='avatar/', null=True)
    mobile = models.CharField(max_length=13, blank=True, null=True)
    # email = models.CharField(max_length=50, blank=True, null=True)
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES, blank=True, null=True)
    description = models.TextField(max_length=200, null=True)
    create_time = models.DateTimeField(auto_now_add=True, null=True)
    score = models.IntegerField(default=0, blank=True, null=True)
    push_email = models.CharField(max_length=40, blank=True, null=True)
    push_switch = models.BooleanField(blank=True, null=True, default=False)

    # admin_token = models.CharField(max_length=32, blank=True, null=True)
    token = models.CharField(max_length=32, blank=True, null=True)
    comany_id = models.IntegerField(blank=True, null=True)
    contact_id=models.IntegerField(blank=True, null=True)
    models.ForeignKey(to="UserToken",to_field="token", on_delete=models.DO_NOTHING)
    models.ForeignKey(to="Company", to_field="comany_id", on_delete=models.DO_NOTHING)
    models.ForeignKey(to="Contact", to_field="contact_id", on_delete=models.DO_NOTHING)
    class Meta:
        db_table = "b_user" 